var PhysicsHelper = Packages.JET.physics.PhysicsHelper;

var sb = Scene.getSpringBodyList().get(0);
var masses = sb.getMassList();
var radius = 50;
var optimalDist = 10;

function doMasses(m1, m2) {
    var vec = m1.getPosition().getSubbed(m2.getPosition());
    var dist = vec.getMagnitude();

    if (dist <= radius) {
        var dir = vec.getNormalized();
        var f = PhysicsHelper.calcSpringForce(  dir, optimalDist,
                                                m1.getVelocity(), m2.getVelocity(),
                                                dist, 1, 0.1);
        
        m1.getForce().sub(f);
        m2.getForce().add(f);
    }
}

for(var i=0; i<masses.size(); i++)
    for(var m=0; m<masses.size(); m++)
        if (i!=m)
            doMasses(masses.get(i), masses.get(m));

